﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using SVC.client;
namespace UI.Forms
{
    public partial class Department_N : DevExpress.XtraEditors.XtraForm
    {
        public delegate void DoAction();//如果有参数的话，定义参数 

        public DoAction FatherRefresh;
        private int count=0;
        public Department_N()
        {
            InitializeComponent();
        }

        private void btn_new_Click(object sender, EventArgs e)
        {

        }



        private void btn_newclose_Click(object sender, EventArgs e)
        {

        }

        private void goodsclass_N_Load(object sender, EventArgs e)
        {
            lue_shop.Properties.DataSource = my.bw.shop_Get("", my.ACID);
            
        }


        private void btn_new_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (!dxValidationProvider1.Validate()) return;
            Depratment dm = new Depratment();
            dm.DepCode = te_did.Text.Trim();
            dm.DepName = te_name.Text.Trim();
            dm.shopcode = lue_shop.EditValue.ToString();
            dm.phone = te_phone.Text.Trim();
            dm.leader = te_leader.Text.Trim();
            string result = my.bw.Depratment_Add(dm, my.ACID);
            if (string.IsNullOrWhiteSpace(result))
            {
                count++;
                te_did.Text = string.Empty;
                te_name.Text = string.Empty;
                lue_shop.EditValue = null;
                te_phone.Text = string.Empty;
                te_leader.Text = string.Empty;
            }
            else
            {
                Comm.ShowErorr(result);
            }
        }

        private void btn_newclose_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (!dxValidationProvider1.Validate()) return;
            Depratment dm = new Depratment();
            dm.DepCode = te_did.Text.Trim();
            dm.DepName = te_name.Text.Trim();
            dm.shopcode = lue_shop.EditValue.ToString();
            dm.phone = te_phone.Text.Trim();
            dm.leader = te_leader.Text.Trim();
            string result = my.bw.Depratment_Add(dm, my.ACID);
            if (string.IsNullOrWhiteSpace(result))
            {
                FatherRefresh();
                this.Close();
            }
            else
            {
                Comm.ShowErorr(result);
            }
        }

        private void lue_shop_EditValueChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(lue_shop.EditValue.ToString()))
            {
                te_did.Text = my.bw.depCode_max_get(lue_shop.EditValue.ToString(), my.ACID);
            }
        }

        private void Department_N_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (count>0)
            {
                FatherRefresh();
            }
        }

    }
}